compiler: Own the accumulated function table

bc981908d47938de933411a4ff72fecd003a1886682abf80034e25392d176cf9
Alexis Sellier committed ago 1 parent a14104e2
lib/std/lang/lower.rad +8 -5
322 322
    /// These become the data sections in the final binary.
323 323
    data: *mut [il::Data],
324 324
    /// First data entry owned by the package currently being lowered.
325 325
    packageDataStart: u32,
326 326
    /// Functions retained for accumulated output.
327 -
    functions: *unsafe mut [*unsafe il::Fn],
327 +
    functions: *mut [*unsafe il::Fn],
328 328
    /// Function and data symbols with their emitted names.
329 329
    symbolNames: *mut [SymbolNameEntry],
330 330
    /// Global error type tag table. Maps nominal types to unique tags.
331 331
    errTags: *mut [ErrTagEntry],
332 332
    /// Next error tag to assign (starts at 1; 0 = success).
378 378
379 379
    return tag;
380 380
}
381 381
382 382
/// Retain a lowered function for accumulated IL output.
383 -
unsafe fn emitFunction 'arena 'phase (self: &mut Lowerer 'arena 'phase, func: *unsafe il::Fn) where 'arena: 'phase {
384 -
    self.functions.append(func, alloc::arenaAllocator(self.arena));
383 +
fn emitFunction 'arena 'phase (self: &mut Lowerer 'arena 'phase, func: *unsafe il::Fn, allocator: alloc::Allocator) where 'arena: 'phase {
384 +
    self.functions.append(func, allocator);
385 385
}
386 386
387 387
/// Get the function role for a top-level function declaration.
388 388
fn lowerFnRole(isRoot: bool, attrs: ?ast::Attributes) -> FnRole {
389 389
    if isRoot and checkAttr(attrs, ast::Attribute::Default) {
938 938
    isRoot: bool,
939 939
    functionArena: &mut alloc::Arena
940 940
) throws (LowerError) where 'arena: 'phase {
941 941
    let mut cursor = try moduleCursor(root, isRoot);
942 942
    while let result = try lowerNext(low, &mut cursor, functionArena) {
943 -
        emitFunction(low, result.function);
943 +
        let allocator = alloc::arenaAllocator(low.arena);
944 +
        emitFunction(low, result.function, allocator);
944 945
    }
945 946
}
946 947
947 948
/// Consume the lowerer and publish its global data as an immutable array.
948 949
export fn finalize 'arena 'phase (low: Lowerer 'arena 'phase) -> il::Program where 'arena: 'phase {
949 950
    let case Lowerer 'arena 'phase { data, functions, .. } = low
950 951
        else panic "expected lowerer";
951 -
    return il::Program { data, fns: functions };
952 +
    unsafe {
953 +
        return il::Program { data, fns: (&functions[..]) as *unsafe [*unsafe il::Fn] };
954 +
    }
952 955
}
953 956
954 957
/////////////////////////////////
955 958
// Qualified Name Construction //
956 959
/////////////////////////////////