Add semantics for struct type and value literals. (#2709)

This handles the basics of type and value for structs. Structurally, these look like parameters and arguments (respectively) because expressions/generics may result in multiple IR nodes being generated.

Because `{}` needs to be cast to a type for storage, I'm also adding some validation that's not specific to `{}`, e.g. that `1` shouldn't be valid as a type for storage (previously, nothing errored for that).

This adds more stringification of types, particularly literals, because they come up in value errors now.

ImplicitAs is the result of me mulling whether I'm taking the right approach on type conversions. I think it needs to return a value so that if the implicit cast rewrites the value, the result is accessible to the caller. I may reorient the current TryTypeConversion logic to be more based on the ImplicitAs logic.
This commit is contained in:
Jon Ross-Perkins
2023-03-30 10:15:11 -07:00
committed by GitHub
parent 33f26bd37b
commit 2eef8c751b
32 changed files with 1200 additions and 206 deletions
+5 -4
View File
@@ -130,16 +130,17 @@ auto SemanticsNodeStack::PopForParseNodeAndNodeId(ParseNodeKind pop_parse_kind)
return {back.parse_node, back.node_id};
}
auto SemanticsNodeStack::PopForParseNodeAndNameId()
auto SemanticsNodeStack::PopForParseNodeAndNameId(ParseNodeKind pop_parse_kind)
-> std::pair<ParseTree::Node, SemanticsStringId> {
auto back = PopEntry(ParseNodeKind::PatternBinding);
auto back = PopEntry(pop_parse_kind);
RequireValidId(back);
return {back.parse_node, back.name_id};
}
auto SemanticsNodeStack::PeekForNameId() -> SemanticsStringId {
auto SemanticsNodeStack::PeekForNameId(ParseNodeKind parse_kind)
-> SemanticsStringId {
auto back = stack_.back();
RequireParseKind(back, ParseNodeKind::PatternBinding);
RequireParseKind(back, parse_kind);
RequireValidId(back);
return back.name_id;
}