-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a further extension to #56128 to make the compiler into a proper stdlib, useable outside of `Base` as `using Compiler` in the same way that `JuliaSyntax` works already. There's a few remaining questions around how loading works, but mechanically, this PR is complete. For those remaining questions, I'll probably put up a separate PR that would migrate JuliaSyntax to it and then simply adopt that here once we've figured out the correct semantics.
- Loading branch information
Showing
45 changed files
with
225 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
Core.PhiNode() = Core.PhiNode(Int32[], Any[]) | ||
|
||
""" | ||
struct Const | ||
val | ||
end | ||
The type representing a constant value. | ||
""" | ||
Core.Const | ||
|
||
""" | ||
struct PartialStruct | ||
typ | ||
fields::Vector{Any} # elements are other type lattice members | ||
end | ||
This extended lattice element is introduced when we have information about an object's | ||
fields beyond what can be obtained from the object type. E.g. it represents a tuple where | ||
some elements are known to be constants or a struct whose `Any`-typed field is initialized | ||
with `Int` values. | ||
- `typ` indicates the type of the object | ||
- `fields` holds the lattice elements corresponding to each field of the object | ||
If `typ` is a struct, `fields` represents the fields of the struct that are guaranteed to be | ||
initialized. For instance, if the length of `fields` of `PartialStruct` representing a | ||
struct with 4 fields is 3, the 4th field may not be initialized. If the length is 4, all | ||
fields are guaranteed to be initialized. | ||
If `typ` is a tuple, the last element of `fields` may be `Vararg`. In this case, it is | ||
guaranteed that the number of elements in the tuple is at least `length(fields)-1`, but the | ||
exact number of elements is unknown. | ||
""" | ||
Core.PartialStruct | ||
|
||
""" | ||
struct InterConditional | ||
slot::Int | ||
thentype | ||
elsetype | ||
end | ||
Similar to `Conditional`, but conveys inter-procedural constraints imposed on call arguments. | ||
This is separate from `Conditional` to catch logic errors: the lattice element name is `InterConditional` | ||
while processing a call, then `Conditional` everywhere else. Thus `InterConditional` does not appear in | ||
`CompilerTypes`—these type's usages are disjoint—though we define the lattice for `InterConditional`. | ||
""" | ||
Core.InterConditional | ||
|
||
InterConditional(var::SlotNumber, @nospecialize(thentype), @nospecialize(elsetype)) = | ||
InterConditional(slot_id(var), thentype, elsetype) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name = "Compiler" | ||
uuid = "807dbc54-b67e-4c79-8afb-eafe4df6f2e1" | ||
version = "0.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
# make sure that typeinf is executed before turning on typeinf_ext | ||
# this ensures that typeinf_ext doesn't recurse before it can add the item to the workq | ||
# especially try to make sure any recursive and leaf functions have concrete signatures, | ||
# since we won't be able to specialize & infer them at runtime | ||
|
||
activate!() = ccall(:jl_set_typeinf_func, Cvoid, (Any,), typeinf_ext_toplevel) | ||
|
||
function bootstrap!() | ||
let time() = ccall(:jl_clock_now, Float64, ()) | ||
println("Compiling the compiler. This may take several minutes ...") | ||
interp = NativeInterpreter() | ||
|
||
# analyze_escapes_tt = Tuple{typeof(analyze_escapes), IRCode, Int, TODO} | ||
optimize_tt = Tuple{typeof(optimize), NativeInterpreter, OptimizationState{NativeInterpreter}, InferenceResult} | ||
fs = Any[ | ||
# we first create caches for the optimizer, because they contain many loop constructions | ||
# and they're better to not run in interpreter even during bootstrapping | ||
#=analyze_escapes_tt,=# optimize_tt, | ||
# then we create caches for inference entries | ||
typeinf_ext, typeinf, typeinf_edge, | ||
] | ||
# tfuncs can't be inferred from the inference entries above, so here we infer them manually | ||
for x in T_FFUNC_VAL | ||
push!(fs, x[3]) | ||
end | ||
for i = 1:length(T_IFUNC) | ||
if isassigned(T_IFUNC, i) | ||
x = T_IFUNC[i] | ||
push!(fs, x[3]) | ||
else | ||
println(stderr, "WARNING: tfunc missing for ", reinterpret(IntrinsicFunction, Int32(i))) | ||
end | ||
end | ||
starttime = time() | ||
for f in fs | ||
if isa(f, DataType) && f.name === typename(Tuple) | ||
tt = f | ||
else | ||
tt = Tuple{typeof(f), Vararg{Any}} | ||
end | ||
for m in _methods_by_ftype(tt, 10, get_world_counter())::Vector | ||
# remove any TypeVars from the intersection | ||
m = m::MethodMatch | ||
typ = Any[m.spec_types.parameters...] | ||
for i = 1:length(typ) | ||
typ[i] = unwraptv(typ[i]) | ||
end | ||
typeinf_type(interp, m.method, Tuple{typ...}, m.sparams) | ||
end | ||
end | ||
endtime = time() | ||
println("Base.Compiler ──── ", sub_float(endtime,starttime), " seconds") | ||
end | ||
activate!() | ||
end |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.