Skip to content

Commit bf15832

Browse files
committed
Default to debug builds and remove --opt
We now (once again) default to debug builds instead of release builds, as slow release builds during development are annoying. In addition, the --opt flag is removed in favour of a --release flag as there was no practical/meaningful difference between --opt=balanced and --opt=aggressive. I experimented with printing a warning when building a debug build, but ultimately found this too annoying. In addition, the output being located in ./build/debug should be enough of a hint that the output is a debug (aka slow) build. This fixes #825. Changelog: changed
1 parent 4f4d270 commit bf15832

File tree

11 files changed

+50
-192
lines changed

11 files changed

+50
-192
lines changed

.github/workflows/tests.yml

+10-10
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ jobs:
8989
std-linux:
9090
strategy:
9191
matrix:
92-
level:
93-
- none
94-
- balanced
92+
flags:
93+
- ''
94+
- '--release'
9595
target:
9696
- image: fedora-amd64
9797
name: amd64-linux-gnu
9898
- image: alpine
9999
name: amd64-linux-musl
100-
name: ${{ matrix.target.name }} std --opt=${{ matrix.level }}
100+
name: ${{ matrix.target.name }} std ${{ matrix.flags }}
101101
timeout-minutes: 15
102102
runs-on: ubuntu-24.04
103103
container:
@@ -109,7 +109,7 @@ jobs:
109109
path: '${{ env.CARGO_HOME }}'
110110
key: ${{ matrix.target.name }}-${{ hashFiles('Cargo.lock', 'rust-toolchain.toml') }}
111111
- name: Run tests
112-
run: 'cd std && cargo run -- test --opt=${{ matrix.level }}'
112+
run: 'cd std && cargo run -- test ${{ matrix.flags }}'
113113

114114
compiler-mac:
115115
strategy:
@@ -140,15 +140,15 @@ jobs:
140140
std-mac:
141141
strategy:
142142
matrix:
143-
level:
144-
- none
145-
- balanced
143+
flags:
144+
- ''
145+
- '--release'
146146
target:
147147
- runner: macos-13
148148
name: amd64-mac-native
149149
- runner: macos-14
150150
name: arm64-mac-native
151-
name: ${{ matrix.target.name }} std --opt=${{ matrix.level }}
151+
name: ${{ matrix.target.name }} std ${{ matrix.flags }}
152152
timeout-minutes: 15
153153
runs-on: ${{ matrix.target.runner }}
154154
env:
@@ -164,7 +164,7 @@ jobs:
164164
- name: Install dependencies
165165
run: ./ci/mac.sh
166166
- name: Run tests
167-
run: 'cd std && cargo run -- test --opt=${{ matrix.level }}'
167+
run: 'cd std && cargo run -- test ${{ matrix.flags }}'
168168

169169
compiler-freebsd:
170170
name: amd64-freebsd-native compiler

compiler/src/compiler.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ LLVM module timings:
583583

584584
// These passes are optional and thus only enabled if optimizations are
585585
// enabled.
586-
if !matches!(self.state.config.opt, Opt::None) {
586+
if !matches!(self.state.config.opt, Opt::Debug) {
587587
measure(&mut self.timings.optimize.inline, || {
588588
InlineMethod::run_all(&mut self.state, mir);
589589
});

compiler/src/config.rs

+7-37
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,7 @@ impl BuildDirectories {
9191
config.build.join(config.target.to_string())
9292
};
9393

94-
let build = config
95-
.opt
96-
.directory_name()
97-
.map(|p| root.join(p))
98-
.unwrap_or_else(|| root.clone());
99-
94+
let build = root.join(config.opt.directory_name());
10095
let objects = build.join("objects");
10196
let llvm_ir = build.join("llvm");
10297
let dot = build.join("dot");
@@ -141,24 +136,15 @@ impl BuildDirectories {
141136
/// A type describing to what degree a program should be optimised.
142137
#[derive(Copy, Clone)]
143138
pub enum Opt {
144-
/// No optimisations are applied.
145-
None,
146-
147-
/// A decent number of optimisations is applied, providing a good balance
148-
/// between runtime performance and compile times.
149-
Balanced,
150-
151-
/// An aggressive number of optimisations is applied, favouring runtime
152-
/// performance over compile times.
153-
Aggressive,
139+
Debug,
140+
Release,
154141
}
155142

156143
impl Opt {
157-
pub(crate) fn directory_name(self) -> Option<&'static str> {
144+
pub(crate) fn directory_name(self) -> &'static str {
158145
match self {
159-
Opt::None => Some("none"),
160-
Opt::Balanced => None,
161-
Opt::Aggressive => Some("aggressive"),
146+
Opt::Debug => "debug",
147+
Opt::Release => "release",
162148
}
163149
}
164150
}
@@ -313,7 +299,7 @@ impl Config {
313299
init_module: ModuleName::std_init(),
314300
output: Output::Derive,
315301
target: Target::native(),
316-
opt: Opt::Balanced,
302+
opt: Opt::Debug,
317303
dot: false,
318304
verify_llvm: false,
319305
write_llvm: false,
@@ -357,22 +343,6 @@ impl Config {
357343
}
358344
}
359345

360-
pub fn set_opt(&mut self, name: &str) -> Result<(), String> {
361-
self.opt = match name {
362-
"none" => Opt::None,
363-
"balanced" => Opt::Balanced,
364-
"aggressive" => Opt::Aggressive,
365-
_ => {
366-
return Err(format!(
367-
"The optimisation level '{}' isn't supported",
368-
name
369-
))
370-
}
371-
};
372-
373-
Ok(())
374-
}
375-
376346
pub(crate) fn main_source_module(&self) -> PathBuf {
377347
let mut main_file = self.source.join(MAIN_MODULE);
378348

compiler/src/llvm/opt.rs

+1-107
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! to OpenMP) removed.
66
//!
77
//! For more details, refer to https://github.com/inko-lang/inko/issues/595.
8-
pub(crate) const BALANCED: &str = "\
8+
pub(crate) const RELEASE: &str = "\
99
inferattrs,\
1010
function<eager-inv>(\
1111
lower-expect,\
@@ -107,109 +107,3 @@ pub(crate) const BALANCED: &str = "\
107107
function(annotation-remarks),\
108108
verify\
109109
";
110-
111-
pub(crate) const AGGRESSIVE: &str = "\
112-
inferattrs,\
113-
function<eager-inv>(\
114-
lower-expect,\
115-
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;no-switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,\
116-
sroa<modify-cfg>,\
117-
early-cse\
118-
),\
119-
ipsccp,\
120-
called-value-propagation,\
121-
globalopt,\
122-
function<eager-inv>(\
123-
mem2reg,\
124-
instcombine<max-iterations=2;no-use-loop-info>,\
125-
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>\
126-
),\
127-
require<globals-aa>,\
128-
function(invalidate<aa>),\
129-
cgscc(\
130-
devirt<4>(\
131-
inline<only-mandatory>,\
132-
inline,\
133-
function-attrs<skip-non-recursive>,\
134-
function<eager-inv;no-rerun>(\
135-
sroa<modify-cfg>,\
136-
early-cse<memssa>,\
137-
speculative-execution,\
138-
jump-threading,\
139-
correlated-propagation,\
140-
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,\
141-
instcombine<max-iterations=2;no-use-loop-info>,\
142-
aggressive-instcombine,\
143-
constraint-elimination,\
144-
libcalls-shrinkwrap,\
145-
tailcallelim,\
146-
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,\
147-
reassociate,\
148-
loop-mssa(\
149-
loop-instsimplify,\
150-
loop-simplifycfg,\
151-
licm<no-allowspeculation>,\
152-
loop-rotate<header-duplication;no-prepare-for-lto>,\
153-
licm<allowspeculation>,\
154-
simple-loop-unswitch<no-nontrivial;trivial>\
155-
),\
156-
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,\
157-
instcombine<max-iterations=2;no-use-loop-info>,\
158-
loop(loop-idiom,indvars,loop-deletion,loop-unroll-full),\
159-
sroa<modify-cfg>,\
160-
vector-combine,\
161-
mldst-motion<no-split-footer-bb>,\
162-
gvn,\
163-
sccp,\
164-
bdce,\
165-
instcombine<max-iterations=2;no-use-loop-info>,\
166-
jump-threading,\
167-
correlated-propagation,\
168-
adce,\
169-
memcpyopt,\
170-
dse,\
171-
move-auto-init,\
172-
loop-mssa(licm<allowspeculation>),\
173-
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>,\
174-
instcombine<max-iterations=2;no-use-loop-info>\
175-
),\
176-
function-attrs,\
177-
function(require<should-not-run-function-passes>)\
178-
)\
179-
),\
180-
deadargelim,\
181-
globalopt,\
182-
globaldce,\
183-
elim-avail-extern,\
184-
rpo-function-attrs,\
185-
recompute-globalsaa,\
186-
function<eager-inv>(\
187-
float2int,\
188-
lower-constant-intrinsics,\
189-
loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),\
190-
loop-distribute,\
191-
inject-tli-mappings,\
192-
loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,\
193-
loop-load-elim,\
194-
instcombine<max-iterations=2;no-use-loop-info>,\
195-
simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>,\
196-
slp-vectorizer,\
197-
vector-combine,\
198-
instcombine<max-iterations=2;no-use-loop-info>,\
199-
loop-unroll<O2>,\
200-
sroa<preserve-cfg>,\
201-
instcombine<max-iterations=2;no-use-loop-info>,\
202-
loop-mssa(licm<allowspeculation>),\
203-
alignment-from-assumptions,\
204-
loop-sink,\
205-
instsimplify,\
206-
div-rem-pairs,\
207-
tailcallelim,\
208-
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>\
209-
),\
210-
globaldce,\
211-
constmerge,\
212-
rel-lookup-table-converter,\
213-
function(annotation-remarks),\
214-
verify\
215-
";

compiler/src/llvm/passes.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ pub(crate) fn lower_all(
310310
// (https://github.com/swiftlang/swift/blob/09d122af7c08e1a6e7fe76f122ddab05b0bbda59/lib/IRGen/IRGen.cpp#L929-L931),
311311
// so we'll assume this is good enough.
312312
let level = match state.config.opt {
313-
Opt::None => OptimizationLevel::None,
313+
Opt::Debug => OptimizationLevel::None,
314314
_ => OptimizationLevel::Default,
315315
};
316316

@@ -551,8 +551,7 @@ impl<'a> Worker<'a> {
551551
// issues similar to https://github.com/llvm/llvm-project/issues/81128)
552552
let mut passes = ["function(mem2reg)"].join(",");
553553
let extra = match self.shared.state.config.opt {
554-
Opt::Balanced => Some(opt::BALANCED),
555-
Opt::Aggressive => Some(opt::AGGRESSIVE),
554+
Opt::Release => Some(opt::RELEASE),
556555
_ => None,
557556
};
558557

docs/source/references/cli.md

+5-14
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,15 @@ using the `inko build` command:
3535
inko build hello.inko
3636
```
3737

38-
The resulting executable is located at `./build/hello`. By default the compiler
39-
uses a set of optimizations similar to the optimizations enabled by using `clang
40-
-O2`. You can either disable optimisations entirely, or enable more aggressive
41-
optimisations at the cost of compile times increasing:
38+
The resulting executable is located at `./build/debug/hello`. By default no
39+
optimizations are applied. To enable optimizations, use the `--release` flag:
4240

4341
```bash
44-
inko build --opt none hello.inko # No optimisations
45-
inko build --opt aggressive hello.inko # Aggressive optimisations
42+
inko build --release hello.inko
4643
```
4744

48-
For `--opt none` the executable is placed in `./build/none/hello`, and
49-
`./build/aggressive/hello` for `--opt aggressive`.
50-
51-
::: tip
52-
In most cases `--opt=aggressive` won't make a difference in runtime performance,
53-
as the differences in optimizations between `balanced` and `aggressive` are
54-
minor. This may change in the future.
55-
:::
45+
When using the `--release` flag, the executable is located at
46+
`./build/release/hello`.
5647

5748
You can specify an alternative output path using the `-o` option:
5849

inko/src/command/build.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::error::Error;
22
use crate::options::print_usage;
33
use compiler::compiler::{CompileError, Compiler};
4-
use compiler::config::{Config, Linker, Output};
4+
use compiler::config::{Config, Linker, Opt, Output};
55
use getopts::Options;
66
use std::path::PathBuf;
77
use types::module_name::ModuleName;
@@ -86,7 +86,7 @@ pub(crate) fn run(arguments: &[String]) -> Result<i32, Error> {
8686
"A directory to add to the list of source directories",
8787
"PATH",
8888
);
89-
options.optopt("", "opt", "The optimization level to use", "LEVEL");
89+
options.optflag("", "release", "Perform a release build");
9090
options.optflag("", "static", "Statically link imported C libraries");
9191
options.optflag("", "dot", "Output the MIR of every module as DOT files");
9292
options.optflag("", "verify-llvm", "Verify LLVM IR when generating code");
@@ -144,8 +144,8 @@ pub(crate) fn run(arguments: &[String]) -> Result<i32, Error> {
144144
config.set_target(&val)?;
145145
}
146146

147-
if let Some(val) = matches.opt_str("opt") {
148-
config.set_opt(&val)?;
147+
if matches.opt_present("release") {
148+
config.opt = Opt::Release;
149149
}
150150

151151
if matches.opt_present("dot") {

inko/src/command/run.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::error::Error;
22
use crate::options::print_usage;
33
use compiler::compiler::{CompileError, Compiler};
4-
use compiler::config::Config;
4+
use compiler::config::{Config, Opt};
55
use getopts::{Options, ParsingStyle};
66
use std::env::temp_dir;
77
use std::fs::{create_dir, remove_dir_all};
@@ -55,6 +55,7 @@ pub(crate) fn run(arguments: &[String]) -> Result<i32, Error> {
5555
let mut options = Options::new();
5656

5757
options.parsing_style(ParsingStyle::StopAtFirstFree);
58+
options.optflag("", "release", "Perform a release build");
5859
options.optflag("h", "help", "Show this help message");
5960
options.optopt(
6061
"f",
@@ -71,7 +72,6 @@ pub(crate) fn run(arguments: &[String]) -> Result<i32, Error> {
7172
);
7273

7374
options.optflag("", "static", "Statically link imported C libraries");
74-
options.optopt("", "opt", "The optimization level to use", "LEVEL");
7575
options.optopt(
7676
"",
7777
"directory",
@@ -102,8 +102,8 @@ pub(crate) fn run(arguments: &[String]) -> Result<i32, Error> {
102102
config.static_linking = true;
103103
}
104104

105-
if let Some(val) = matches.opt_str("opt") {
106-
config.set_opt(&val)?;
105+
if matches.opt_present("release") {
106+
config.opt = Opt::Release;
107107
}
108108

109109
let dir_name = matches

inko/src/command/test.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub(crate) fn run(arguments: &[String]) -> Result<i32, Error> {
3030
"The target platform to compile for",
3131
"TARGET",
3232
);
33-
options.optopt("", "opt", "The optimization level to use", "LEVEL");
33+
options.optflag("", "release", "Perform a release build");
3434

3535
let matches = options.parse(arguments)?;
3636

@@ -45,10 +45,8 @@ pub(crate) fn run(arguments: &[String]) -> Result<i32, Error> {
4545
config.set_target(&val)?;
4646
}
4747

48-
if let Some(val) = matches.opt_str("opt") {
49-
config.set_opt(&val)?;
50-
} else {
51-
config.opt = Opt::None;
48+
if matches.opt_present("release") {
49+
config.opt = Opt::Release;
5250
}
5351

5452
let main_file = config.main_test_module();

0 commit comments

Comments
 (0)