Skip to content

Commit 6093f93

Browse files
authored
Merge pull request #18 from oven-sh/ali/sanic-gotta-go-fast
shard sema and codegen
2 parents 365343a + c0b39d9 commit 6093f93

File tree

21 files changed

+2648
-561
lines changed

21 files changed

+2648
-561
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ zig-out/
2020
# Although this was renamed to .zig-cache, let's leave it here for a few
2121
# releases to make it less annoying to work with multiple branches.
2222
zig-cache/
23+
.claude/
24+
bun-cache/

build.zig

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ pub fn build(b: *std.Build) !void {
123123
"llvm-has-xtensa",
124124
"Whether LLVM has the experimental target xtensa enabled",
125125
) orelse false;
126+
const llvm_has_polly = b.option(
127+
bool,
128+
"llvm-has-polly",
129+
"Whether LLVM was built with Polly and requires linking it",
130+
) orelse false;
126131
const enable_ios_sdk = b.option(bool, "enable-ios-sdk", "Run tests requiring presence of iOS SDK and frameworks") orelse false;
127132
const enable_macos_sdk = b.option(bool, "enable-macos-sdk", "Run tests requiring presence of macOS SDK and frameworks") orelse enable_ios_sdk;
128133
const enable_symlinks_windows = b.option(bool, "enable-symlinks-windows", "Run tests requiring presence of symlinks on Windows") orelse false;
@@ -332,6 +337,7 @@ pub fn build(b: *std.Build) !void {
332337
.llvm_has_csky = llvm_has_csky,
333338
.llvm_has_arc = llvm_has_arc,
334339
.llvm_has_xtensa = llvm_has_xtensa,
340+
.llvm_has_polly = llvm_has_polly,
335341
});
336342
}
337343
if (target.result.os.tag == .windows) {
@@ -739,7 +745,7 @@ fn addCompilerMod(b: *std.Build, options: AddCompilerModOptions) *std.Build.Modu
739745
fn addCompilerStep(b: *std.Build, options: AddCompilerModOptions) *std.Build.Step.Compile {
740746
const exe = b.addExecutable(.{
741747
.name = "zig",
742-
.max_rss = 10_000_000_000,
748+
.max_rss = 11_000_000_000,
743749
.root_module = addCompilerMod(b, options),
744750
});
745751
exe.stack_size = stack_size;
@@ -858,6 +864,7 @@ fn addStaticLlvmOptionsToModule(mod: *std.Build.Module, options: struct {
858864
llvm_has_csky: bool,
859865
llvm_has_arc: bool,
860866
llvm_has_xtensa: bool,
867+
llvm_has_polly: bool,
861868
}) !void {
862869
// Adds the Zig C++ sources which both stage1 and stage2 need.
863870
//
@@ -898,6 +905,10 @@ fn addStaticLlvmOptionsToModule(mod: *std.Build.Module, options: struct {
898905
mod.linkSystemLibrary(lib_name, .{});
899906
};
900907

908+
if (options.llvm_has_polly) for (llvm_libs_polly) |lib_name| {
909+
mod.linkSystemLibrary(lib_name, .{});
910+
};
911+
901912
mod.linkSystemLibrary("z", .{});
902913
mod.linkSystemLibrary("zstd", .{});
903914

@@ -1419,6 +1430,10 @@ const llvm_libs_xtensa = [_][]const u8{
14191430
"LLVMXtensaDesc",
14201431
"LLVMXtensaInfo",
14211432
};
1433+
const llvm_libs_polly = [_][]const u8{
1434+
"Polly",
1435+
"PollyISL",
1436+
};
14221437

14231438
fn generateLangRef(b: *std.Build) std.Build.LazyPath {
14241439
const doctest_exe = b.addExecutable(.{

src/Air.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,6 +2154,7 @@ pub fn unwrapShuffleTwo(air: *const Air, zcu: *const Zcu, inst_index: Inst.Index
21542154
}
21552155

21562156
pub const typesFullyResolved = types_resolved.typesFullyResolved;
2157+
pub const resolveTypesFully = types_resolved.resolveTypesFully;
21572158
pub const typeFullyResolved = types_resolved.checkType;
21582159
pub const valFullyResolved = types_resolved.checkVal;
21592160
pub const legalize = Legalize.legalize;

src/Air/types_resolved.zig

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@ pub fn typesFullyResolved(air: Air, zcu: *Zcu) bool {
1010
return checkBody(air, air.getMainBody(), zcu);
1111
}
1212

13+
/// Under parallel Sema, `resolve_type_fully` and `codegen_func` run
14+
/// concurrently, so types may be mid-resolution rather than failed. Walk the
15+
/// same AIR shape as `typesFullyResolved` but force-resolve each struct/union
16+
/// (blocking on `claimOrWait`-gated resolution). Returns false only if
17+
/// resolution itself errors.
18+
pub fn resolveTypesFully(air: Air, pt: Zcu.PerThread) bool {
19+
tls_resolve_pt = pt;
20+
defer tls_resolve_pt = null;
21+
return checkBody(air, air.getMainBody(), pt.zcu);
22+
}
23+
24+
/// `checkType` is reached via a long instruction walk; thread the optional
25+
/// PerThread via tls instead of plumbing it through every switch arm.
26+
threadlocal var tls_resolve_pt: ?Zcu.PerThread = null;
27+
1328
fn checkBody(air: Air, body: []const Air.Inst.Index, zcu: *Zcu) bool {
1429
const tags = air.instructions.items(.tag);
1530
const datas = air.instructions.items(.data);
@@ -513,6 +528,10 @@ pub fn checkType(ty: Type, zcu: *Zcu) bool {
513528
},
514529
.@"struct" => switch (ip.indexToKey(ty.toIntern())) {
515530
.struct_type => {
531+
if (tls_resolve_pt) |pt| {
532+
ty.resolveFully(pt) catch return false;
533+
return true;
534+
}
516535
const struct_obj = zcu.typeToStruct(ty).?;
517536
return switch (struct_obj.layout) {
518537
.@"packed" => struct_obj.backingIntTypeUnordered(ip) != .none,
@@ -530,6 +549,12 @@ pub fn checkType(ty: Type, zcu: *Zcu) bool {
530549
},
531550
else => unreachable,
532551
},
533-
.@"union" => return zcu.typeToUnion(ty).?.flagsUnordered(ip).status == .fully_resolved,
552+
.@"union" => {
553+
if (tls_resolve_pt) |pt| {
554+
ty.resolveFully(pt) catch return false;
555+
return true;
556+
}
557+
return zcu.typeToUnion(ty).?.flagsUnordered(ip).status == .fully_resolved;
558+
},
534559
};
535560
}

0 commit comments

Comments
 (0)