Skip to content

Commit caa8a97

Browse files
Build compiler with -Dpreview_mt (#16380)
We added support for multi-threaded codegen in #14748 but never enabled it in the default build configuration. It's expected to be more efficient than the current fork-based parallelization. And it works on Windows. I suppose we could also consider passing `-Dexecution_context`? But the `mt_codegen` code probably needs an adjustment for that (at least resize the default context to `n_threads`. Compiler versions before 1.8 are broken with `-Dpreview_mt`, so we need to disable it for older versions.
1 parent 6314a46 commit caa8a97

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ check ?= ## Enable only check when running format
3737
order ?=random ## Enable order for spec execution (values: "default" | "random" | seed number)
3838
deref_symlinks ?= ## Dereference symbolic links for `make install`
3939
docs_sanitizer ?= ## Enable sanitization for documentation generation
40+
sequential_codegen ?=$(if $(filter 0,$(supports_preview_mt)),true,)## Enforce sequential codegen in compiler builds. Base compiler before Crystal 1.8 cannot build with `-Dpreview_mt`
4041

4142
O := .build
4243
SOURCES := $(shell find src -name '*.cr')
@@ -45,12 +46,13 @@ MAN1PAGES := $(patsubst doc/man/%.adoc,man/%.1,$(wildcard doc/man/*.adoc))
4546
override FLAGS += -D strict_multi_assign -D preview_overload_order $(if $(release),--release )$(if $(stats),--stats )$(if $(progress),--progress )$(if $(threads),--threads $(threads) )$(if $(debug),-d )$(if $(static),--static )$(if $(LDFLAGS),--link-flags="$(LDFLAGS)" )$(if $(target),--cross-compile --target $(target) )
4647
# NOTE: USE_PCRE1 is only used for testing compatibility with legacy environments that don't provide libpcre2.
4748
# Newly built compilers should never be distributed with libpcre to ensure syntax consistency.
48-
override COMPILER_FLAGS += $(if $(interpreter),,-Dwithout_interpreter )$(if $(docs_sanitizer),,-Dwithout_libxml2 ) -Dwithout_openssl -Dwithout_zlib $(if $(USE_PCRE1),-Duse_pcre,-Duse_pcre2)
49+
override COMPILER_FLAGS += $(if $(interpreter),,-Dwithout_interpreter )$(if $(docs_sanitizer),,-Dwithout_libxml2 ) -Dwithout_openssl -Dwithout_zlib$(if $(sequential_codegen),, -Dpreview_mt) $(if $(USE_PCRE1),-Duse_pcre,-Duse_pcre2)
4950
SPEC_WARNINGS_OFF := --exclude-warnings spec/std --exclude-warnings spec/compiler --exclude-warnings spec/primitives --exclude-warnings src/float/printer --exclude-warnings src/random.cr
5051
override SPEC_FLAGS += $(if $(verbose),-v )$(if $(junit_output),--junit_output $(junit_output) )$(if $(order),--order=$(order) )
5152
CRYSTAL_CONFIG_LIBRARY_PATH := '$$ORIGIN/../lib/crystal'
5253
CRYSTAL_CONFIG_BUILD_COMMIT ?= $(shell git rev-parse --short HEAD 2> /dev/null)
5354
CRYSTAL_CONFIG_PATH := '$$ORIGIN/../share/crystal/src'
55+
BASE_CRYSTAL_VERSION ?= $(shell $(CRYSTAL) env CRYSTAL_VERSION)
5456
CRYSTAL_VERSION ?= $(shell cat src/VERSION)
5557
SOURCE_DATE_EPOCH ?= $(shell (cat src/SOURCE_DATE_EPOCH || (git show -s --format=%ct HEAD || stat -c "%Y" Makefile || stat -f "%m" Makefile)) 2> /dev/null)
5658
check_lld := command -v ld.lld >/dev/null && case "$$(uname -s)" in MINGW32*|MINGW64*|Linux) echo 1;; esac
@@ -71,6 +73,9 @@ ifeq ($(LLVM_VERSION),)
7173
LLVM_VERSION ?= $(if $(LLVM_CONFIG),$(shell "$(LLVM_CONFIG)" --version 2> /dev/null))
7274
endif
7375

76+
# Crystal versions before 1.8 cannot build a functional compiler with `-Dpreview_mt` (https://github.com/crystal-lang/crystal/pull/16380)
77+
supports_preview_mt := $(if $(filter 1.8.0,$(shell printf "%s\n%s" "1.8.0" "$(BASE_CRYSTAL_VERSION)" | sort -V | tail -n1)),0,1)
78+
7479
LLVM_EXT_DIR = src/llvm/ext
7580
LLVM_EXT_OBJ = $(LLVM_EXT_DIR)/llvm_ext.o
7681
CXXFLAGS += $(if $(debug),-g -O0)

Makefile.win

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ interpreter ?= ## Enable interpreter feature
3636
check ?= ## Enable only check when running format
3737
order ?=random ## Enable order for spec execution (values: "default" | "random" | seed number)
3838
docs_sanitizer ?= ## Enable sanitization for documentation generation
39+
sequential_codegen ?= ## Enforce sequential codegen in compiler builds. Base compiler before Crystal 1.8 cannot build with `-Dpreview_mt`
3940

4041
MAKEFLAGS += --no-builtin-rules
4142
.SUFFIXES:
@@ -60,7 +61,7 @@ SPEC_SOURCES := $(call GLOB,spec\\*.cr)
6061
override FLAGS += -D strict_multi_assign -D preview_overload_order $(if $(release),--release )$(if $(stats),--stats )$(if $(progress),--progress )$(if $(threads),--threads $(threads) )$(if $(debug),-d )$(if $(static),--static )$(if $(LDFLAGS),--link-flags="$(LDFLAGS)" )$(if $(target),--cross-compile --target $(target) )
6162
# NOTE: USE_PCRE1 is only used for testing compatibility with legacy environments that don't provide libpcre2.
6263
# Newly built compilers should never be distributed with libpcre to ensure syntax consistency.
63-
override COMPILER_FLAGS += $(if $(interpreter),,-Dwithout_interpreter )$(if $(docs_sanitizer),,-Dwithout_libxml2 ) -Dwithout_openssl -Dwithout_zlib $(if $(USE_PCRE1),-Duse_pcre,-Duse_pcre2)
64+
override COMPILER_FLAGS += $(if $(interpreter),,-Dwithout_interpreter )$(if $(docs_sanitizer),,-Dwithout_libxml2 ) -Dwithout_openssl -Dwithout_zlib$(if $(sequential_codegen),, -Dpreview_mt) $(if $(USE_PCRE1),-Duse_pcre,-Duse_pcre2)
6465
SPEC_WARNINGS_OFF := --exclude-warnings spec\std --exclude-warnings spec\compiler --exclude-warnings spec\primitives --exclude-warnings src\float\printer
6566
SPEC_FLAGS := $(if $(verbose),-v )$(if $(junit_output),--junit_output $(junit_output) )$(if $(order),--order=$(order) )
6667
CRYSTAL_CONFIG_LIBRARY_PATH := $$ORIGIN\lib

0 commit comments

Comments
 (0)