Skip to content

Commit

Permalink
Merge pull request #6894 from roc-lang/list-size-on-heap
Browse files Browse the repository at this point in the history
List refcounting perf fix: List size on heap
  • Loading branch information
bhansconnect authored Jul 14, 2024
2 parents be4f687 + c5c2617 commit 0284248
Show file tree
Hide file tree
Showing 106 changed files with 4,460 additions and 4,022 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
target
generated-docs
zig-cache
.zig-cache
.direnv
.envrc
*.rs.bk
Expand Down
128 changes: 0 additions & 128 deletions crates/compiler/alias_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,6 @@ fn call_spec<'a>(

let closure_env = env.symbols[&passed_function.captured_environment];

let return_layout = &passed_function.return_layout;
let argument_layouts = passed_function.argument_layouts;

macro_rules! call_function {
Expand All @@ -879,30 +878,6 @@ fn call_spec<'a>(
}

match op {
ListMap { xs } => {
let list = env.symbols[xs];

let loop_body = |builder: &mut FuncDefBuilder, block, state| {
let input_bag = builder.add_get_tuple_field(block, list, LIST_BAG_INDEX)?;

let element = builder.add_bag_get(block, input_bag)?;

let new_element = call_function!(builder, block, [element]);

list_append(builder, block, update_mode_var, state, new_element)
};

let output_element_type =
layout_spec(env, builder, interner, interner.get_repr(*return_layout))?;

let state_layout = LayoutRepr::Builtin(Builtin::List(*return_layout));
let state_type = layout_spec(env, builder, interner, state_layout)?;

let init_state = new_list(builder, block, output_element_type)?;

add_loop(builder, block, state_type, init_state, loop_body)
}

ListSortWith { xs } => {
let list = env.symbols[xs];

Expand All @@ -928,109 +903,6 @@ fn call_spec<'a>(

add_loop(builder, block, state_type, init_state, loop_body)
}

ListMap2 { xs, ys } => {
let list1 = env.symbols[xs];
let list2 = env.symbols[ys];

let loop_body = |builder: &mut FuncDefBuilder, block, state| {
let input_bag_1 =
builder.add_get_tuple_field(block, list1, LIST_BAG_INDEX)?;
let input_bag_2 =
builder.add_get_tuple_field(block, list2, LIST_BAG_INDEX)?;

let element_1 = builder.add_bag_get(block, input_bag_1)?;
let element_2 = builder.add_bag_get(block, input_bag_2)?;

let new_element = call_function!(builder, block, [element_1, element_2]);

list_append(builder, block, update_mode_var, state, new_element)
};

let output_element_type =
layout_spec(env, builder, interner, interner.get_repr(*return_layout))?;

let state_layout = LayoutRepr::Builtin(Builtin::List(*return_layout));
let state_type = layout_spec(env, builder, interner, state_layout)?;

let init_state = new_list(builder, block, output_element_type)?;

add_loop(builder, block, state_type, init_state, loop_body)
}

ListMap3 { xs, ys, zs } => {
let list1 = env.symbols[xs];
let list2 = env.symbols[ys];
let list3 = env.symbols[zs];

let loop_body = |builder: &mut FuncDefBuilder, block, state| {
let input_bag_1 =
builder.add_get_tuple_field(block, list1, LIST_BAG_INDEX)?;
let input_bag_2 =
builder.add_get_tuple_field(block, list2, LIST_BAG_INDEX)?;
let input_bag_3 =
builder.add_get_tuple_field(block, list3, LIST_BAG_INDEX)?;

let element_1 = builder.add_bag_get(block, input_bag_1)?;
let element_2 = builder.add_bag_get(block, input_bag_2)?;
let element_3 = builder.add_bag_get(block, input_bag_3)?;

let new_element =
call_function!(builder, block, [element_1, element_2, element_3]);

list_append(builder, block, update_mode_var, state, new_element)
};

let output_element_type =
layout_spec(env, builder, interner, interner.get_repr(*return_layout))?;

let state_layout = LayoutRepr::Builtin(Builtin::List(*return_layout));
let state_type = layout_spec(env, builder, interner, state_layout)?;

let init_state = new_list(builder, block, output_element_type)?;

add_loop(builder, block, state_type, init_state, loop_body)
}
ListMap4 { xs, ys, zs, ws } => {
let list1 = env.symbols[xs];
let list2 = env.symbols[ys];
let list3 = env.symbols[zs];
let list4 = env.symbols[ws];

let loop_body = |builder: &mut FuncDefBuilder, block, state| {
let input_bag_1 =
builder.add_get_tuple_field(block, list1, LIST_BAG_INDEX)?;
let input_bag_2 =
builder.add_get_tuple_field(block, list2, LIST_BAG_INDEX)?;
let input_bag_3 =
builder.add_get_tuple_field(block, list3, LIST_BAG_INDEX)?;
let input_bag_4 =
builder.add_get_tuple_field(block, list4, LIST_BAG_INDEX)?;

let element_1 = builder.add_bag_get(block, input_bag_1)?;
let element_2 = builder.add_bag_get(block, input_bag_2)?;
let element_3 = builder.add_bag_get(block, input_bag_3)?;
let element_4 = builder.add_bag_get(block, input_bag_4)?;

let new_element = call_function!(
builder,
block,
[element_1, element_2, element_3, element_4]
);

list_append(builder, block, update_mode_var, state, new_element)
};

let output_element_type =
layout_spec(env, builder, interner, interner.get_repr(*return_layout))?;

let state_layout = LayoutRepr::Builtin(Builtin::List(*return_layout));
let state_type = layout_spec(env, builder, interner, state_layout)?;

let init_state = new_list(builder, block, output_element_type)?;

add_loop(builder, block, state_type, init_state, loop_body)
}
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions crates/compiler/build/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,10 @@ fn link_macos(
.args(input_paths)
.args(extra_link_flags());

if get_xcode_version() >= 15.0 {
ld_command.arg("-ld_classic");
}

let sdk_path = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib";
if Path::new(sdk_path).exists() {
ld_command.arg(format!("-L{sdk_path}"));
Expand Down Expand Up @@ -1187,6 +1191,24 @@ fn get_macos_version() -> String {
.join(".")
}

fn get_xcode_version() -> f32 {
let mut cmd = Command::new("xcodebuild");
cmd.arg("-version");
debug_print_command(&cmd);

cmd.output()
.map_err(|_| ())
.and_then(|out| String::from_utf8(out.stdout).map_err(|_| ()))
.and_then(|str| {
str.split_whitespace()
.nth(1)
.map(|s| s.to_string())
.ok_or(())
})
.and_then(|version| version.parse::<f32>().map_err(|_| ()))
.unwrap_or(0.0)
}

fn link_wasm32(
_target: Target,
output_path: PathBuf,
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/builtins/bitcode/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn generateObjectFile(

const obj_file = obj.getEmittedBin();

var suffix =
const suffix =
if (target.os_tag == .windows)
"obj"
else
Expand Down
Loading

0 comments on commit 0284248

Please sign in to comment.