Skip to content

fix field alignment kludge by implementing lazy values #3115

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

Merged
merged 33 commits into from
Aug 27, 2019

Conversation

andrewrk
Copy link
Member

@andrewrk andrewrk commented Aug 23, 2019

This is an implementation of lazy values (#2174) which is required to fix many false positive circular dependency bugs, as well as field alignment bugs. It also implements ability to set alignment of struct and union fields (#1512). It also improves the error notes for "unable to evaluate constant expression" (#1732).

Checklist:

  • more lazy value additions to get test suite passing again
  • slice type and ptr type instructions need to implicit cast alignment
  • compile error for specifying alignment on enum fields
  • hook up the error note trace for unable to evaluate constant expression
  • fix regressions of error notes with "called from here"
  • add tests for specifying field alignment. The part of resolve_struct_type that calculates field offsets needs to have the logic from get_struct_type
  • make sure tetris builds
  • make sure clashos builds
  • make sure oxid builds
  • make sure swarkland builds
  • make sure fundude builds

This breaks behavior tests as well as compile error notes for generic
function calls. However it introduces better circular dependency compile
errors.

The next step is to add Lazy Values to fix the regressions.
this case now works:

```zig
const Node = struct {
    field: fn (*Node) *Node,
};
```
this case now works:

```zig
const A = struct {
    b: B,
};
const B = fn (A) void;
```
this case works now:

```zig
const A = struct {
    b_list_pointer: *const []B,
};
const B = struct {
    a_pointer: *const A,
};

const b_list: []B = [_]B{};
const a = A{ .b_list_pointer = &b_list };
const obj = B{ .a_pointer = &a };
```
this case works now:

```zig
const Node = struct {
    node: ?*Node,
};
```
this case regressed and now fixed:

```zig
const a: ?*i32 = undefined;
const b: ?*f32 = @ptrCast(?*f32, a);
```
this case works now:

```zig
const Expr = union(enum) {
    Literal: u8,
    Question: *Expr,
};
```
this case works now:

```zig
const Foo = struct {
    field: @typeof(func).ReturnType,
};
fn func(self: *Foo) void {}
```
this case works now:

```zig
const Foo = struct {
    field: Bar(@Alignof(*Foo)),
};
fn Bar(comptime alignment: u29) type {
    return struct {
        field: *align(alignment) Foo,
    };
}
```
...with optional unwrapping with var initialized to undefined
@andrewrk andrewrk marked this pull request as ready for review August 27, 2019 02:50
and add check for alignment specified on enum fields
@andrewrk andrewrk merged commit 35a374e into master Aug 27, 2019
@andrewrk andrewrk deleted the fix-field-alignment-kludge branch August 27, 2019 17:02
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.

1 participant