backport copy elision changes

This commit contains everything from the copy-elision-2
branch that does not have to do with copy elision directly,
but is generally useful for master branch.

 * All const values know their parents, when applicable, not
   just structs and unions.
 * Null pointers in const values are represented explicitly,
   rather than as a HardCodedAddr value of 0.
 * Rename "maybe" to "optional" in various code locations.
 * Separate DeclVarSrc and DeclVarGen
 * Separate PtrCastSrc and PtrCastGen
 * Separate CmpxchgSrc and CmpxchgGen
 * Represent optional error set as an integer, using the 0 value.
   In a const value, it uses nullptr.
 * Introduce type_has_one_possible_value and use it where applicable.
 * Fix debug builds not setting memory to 0xaa when storing
   undefined.
 * Separate the type of a variable from the const value of a variable.
 * Use copy_const_val where appropriate.
 * Rearrange structs to pack data more efficiently.
 * Move test/cases/* to test/behavior/*
 * Use `std.debug.assertOrPanic` in behavior tests instead of
   `std.debug.assert`.
 * Fix outdated slice syntax in docs.
This commit is contained in:
Andrew Kelley
2019-01-29 21:47:26 -05:00
parent 9c328b4291
commit 581edd643f
108 changed files with 3836 additions and 2933 deletions

View File

@@ -381,7 +381,7 @@ static AstNode *ast_parse_if_expr_helper(ParseContext *pc, AstNode *(*body_parse
else_body = ast_expect(pc, body_parser);
}
assert(res->type == NodeTypeTestExpr);
assert(res->type == NodeTypeIfOptional);
if (err_payload != nullptr) {
AstNodeTestExpr old = res->data.test_expr;
res->type = NodeTypeIfErrorExpr;
@@ -990,7 +990,7 @@ static AstNode *ast_parse_if_statement(ParseContext *pc) {
if (requires_semi && else_body == nullptr)
expect_token(pc, TokenIdSemicolon);
assert(res->type == NodeTypeTestExpr);
assert(res->type == NodeTypeIfOptional);
if (err_payload != nullptr) {
AstNodeTestExpr old = res->data.test_expr;
res->type = NodeTypeIfErrorExpr;
@@ -2204,7 +2204,7 @@ static AstNode *ast_parse_if_prefix(ParseContext *pc) {
Optional<PtrPayload> opt_payload = ast_parse_ptr_payload(pc);
PtrPayload payload;
AstNode *res = ast_create_node(pc, NodeTypeTestExpr, first);
AstNode *res = ast_create_node(pc, NodeTypeIfOptional, first);
res->data.test_expr.target_node = condition;
if (opt_payload.unwrap(&payload)) {
res->data.test_expr.var_symbol = token_buf(payload.payload);
@@ -2999,7 +2999,7 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
visit_field(&node->data.if_err_expr.then_node, visit, context);
visit_field(&node->data.if_err_expr.else_node, visit, context);
break;
case NodeTypeTestExpr:
case NodeTypeIfOptional:
visit_field(&node->data.test_expr.target_node, visit, context);
visit_field(&node->data.test_expr.then_node, visit, context);
visit_field(&node->data.test_expr.else_node, visit, context);