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

constants, mapper: type bugfixes #11

Merged
merged 11 commits into from Oct 3, 2021
Merged

constants, mapper: type bugfixes #11

merged 11 commits into from Oct 3, 2021

Conversation

woodruffw
Copy link
Owner

My type table state machine thingy is a little bit wrong, since it doesn't correctly handle forward-referenced types (e.g. if a pointer type has struct foo as its pointee).

Needs fixing.

@woodruffw woodruffw added C:mapper Concerns the llvm-mapper crate. C:support Concerns the llvm-support crate. labels Sep 13, 2021
@woodruffw
Copy link
Owner Author

This is going to be a little annoying with the current implementation, since we fully "unroll" each type as we encounter it. As a result, forward references are prematurely unrolled and we don't have a chance to fix them up.

@woodruffw
Copy link
Owner Author

Braindumping so that I have a better starting point for this later. There are a few annoying aspects of LLVM's type table layout:

  • Types are uniquely identified by their index in the type table. Types can have subtypes and those subtypes might not be fully declared yet, so LLVM's own implementation assumes that an index that doesn't already contain a type is a forward-declared structure and puts a default struct at that index. These forward indexes can in turn be "sparse", since a type might further reference multiple forward types before each is visited.
  • In LLVM, the equality of types is defined by their pointer identity: (T1 == T2) <=> (&T1 == &T2). This works because types are uniqued on a global/per-module basis, and are really just references to an internal table where all types are stored. Duplicating this in Rust is a massive headache, since it implicitly depends on mutability while other objects hold immutable references: the type table is visited incrementally to fill in e.g. forward types, and every previous type that contains subtypes gets updated "for free" thanks to the data behind their common pointer being updated.

@woodruffw woodruffw merged commit 4368f46 into main Oct 3, 2021
@woodruffw woodruffw deleted the type-fixes branch October 3, 2021 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:mapper Concerns the llvm-mapper crate. C:support Concerns the llvm-support crate.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant