Skip to content

Conversation

@mlugg
Copy link
Member

@mlugg mlugg commented Aug 14, 2023

Some builtin types have a special InternPool index (e.g. .type_info_type) so that AstGen can refer to them before semantic analysis. Unfortunately, this previously led to a second index existing to refer to the type once it was resolved, complicating Sema by having the concept of an "unresolved" type index.

This change makes Sema modify these InternPool indices in-place to contain the expanded representation when resolved. The analysis of the corresponding decls is caught in Module.semaDecl, and a field is set on Sema telling it which index to place struct/union/enum types at. This system could break if std.builtin contained complex decls which evaluate multiple struct types, but this will be caught by the assertions in InternPool.resolveBuiltinType.

The AstGen result types which were disabled in 6917a8c have been re-enabled.

Resolves: #16603

@mlugg mlugg force-pushed the internpool-same-resolved-index branch 2 times, most recently from 3834050 to 9262f08 Compare August 14, 2023 17:56
mlugg added 2 commits August 15, 2023 11:42
This type not being resolved was a bug which was being triggered by the
next commit.
Some builtin types have a special InternPool index (e.g.
`.type_info_type`) so that AstGen can refer to them before semantic
analysis. Unfortunately, this previously led to a second index existing
to refer to the type once it was resolved, complicating Sema by having
the concept of an "unresolved" type index.

This change makes Sema modify these InternPool indices in-place to
contain the expanded representation when resolved. The analysis of the
corresponding decls is caught in `Module.semaDecl`, and a field is set
on Sema telling it which index to place struct/union/enum types at. This
system could break if `std.builtin` contained complex decls which
evaluate multiple struct types, but this will be caught by the
assertions in `InternPool.resolveBuiltinType`.

The AstGen result types which were disabled in 6917a8c have been
re-enabled.

Resolves: ziglang#16603
@mlugg mlugg force-pushed the internpool-same-resolved-index branch from 8fd0323 to 083ee8e Compare August 15, 2023 10:45
Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. I think this came out to a pretty reasonable patch.

As a follow-up it might be nice to explore eliminating those enum tags from SimpleType and instead setting up the enum/struct/union in an unresolved state. This way it does not end up creating a dummy index that ultimately just gets copied over to the real thing. I don't think that exploration needs to block this PR though.

@andrewrk andrewrk merged commit 340a456 into ziglang:master Aug 15, 2023
@mlugg mlugg deleted the internpool-same-resolved-index branch May 18, 2025 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Give consistent InternPool indices to builtin types

2 participants