Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: inference: allow PartialStruct to have Union{} field to indicate strict undef #57541

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aviatesk
Copy link
Member

@aviatesk aviatesk commented Feb 26, 2025

This change allows PartialStruct to represent structs with strictly uninitialized fields.
Also, this lets us fix the length of typ::PartialStruct's fields to always match the number of fields in typ.typ. Instead of the current design where the length of fields changes depending on the number of initialized fields, it seems simpler to have PartialStructs representing the same typ always have the same fields length. So, I've included that refactoring as well.

Fixes the newly detected error in Oscar.jl.

Remaining TODOs:

  • Add tests
  • Fix the lattice order

…strict undef

This change allows `PartialStruct` to represent structs with
strictly uninitialized fields.
Also, this lets us fix the length of `typ::PartialStruct`'s `fields` to
always match the number of fields in `typ.typ`. Instead of the current
design where the length of `fields` changes depending on the number of
initialized fields, it seems simpler to have `PartialStruct`s
representing the same `typ` always have the same `fields` length.
So, I've included that refactoring as well.

- fixes the newly detected error in Oscar.jl
@aviatesk aviatesk force-pushed the avi/strict-undef-fields branch from f0b8a63 to 245049e Compare February 26, 2025 20:10
@aviatesk aviatesk force-pushed the avi/strict-undef-fields branch from 245049e to c8dcd2c Compare February 26, 2025 20:47
@serenity4
Copy link
Contributor

The initial choice to make length(fields) <= length(fieldcount(typ)) was to improve performance (particularly so for large structs, but small structs also benefit from it). However, if benchmarks/build times show no noticeable regression, then the consistency is nice to have 👍

fldcnt = fieldcount_noerror(objt)::Int
fields = Any[fieldtype(objt0, i) for i = 1:fldcnt]
if fields[fldidx] === Union{}
return nothing # refine this field
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand the comment here, doesn't refining mean returning a PartialStruct? (though it makes sense to return nothing as a Union{} field type already implies undef[fldidx] === true)

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.

2 participants