diff --git a/Makefile b/Makefile index a98fd46f2caa..a08a18b438f7 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ check ?= ## Enable only check when running format order ?=random ## Enable order for spec execution (values: "default" | "random" | seed number) deref_symlinks ?= ## Dereference symbolic links for `make install` docs_sanitizer ?= ## Enable sanitization for documentation generation -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` +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 -Dexecution_context` O := .build SOURCES := $(shell find src -name '*.cr') @@ -46,7 +46,7 @@ MAN1PAGES := $(patsubst doc/man/%.adoc,man/%.1,$(wildcard doc/man/*.adoc)) 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) ) # NOTE: USE_PCRE1 is only used for testing compatibility with legacy environments that don't provide libpcre2. # Newly built compilers should never be distributed with libpcre to ensure syntax consistency. -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) +override COMPILER_FLAGS += $(if $(interpreter),,-Dwithout_interpreter )$(if $(docs_sanitizer),,-Dwithout_libxml2 ) -Dwithout_openssl -Dwithout_zlib$(if $(sequential_codegen),, -Dpreview_mt -Dexecution_context) $(if $(USE_PCRE1),-Duse_pcre,-Duse_pcre2) 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 override SPEC_FLAGS += $(if $(verbose),-v )$(if $(junit_output),--junit_output $(junit_output) )$(if $(order),--order=$(order) ) CRYSTAL_CONFIG_LIBRARY_PATH := '$$ORIGIN/../lib/crystal' diff --git a/src/compiler/crystal.cr b/src/compiler/crystal.cr index e6924d4d5248..799c79de1f38 100644 --- a/src/compiler/crystal.cr +++ b/src/compiler/crystal.cr @@ -8,4 +8,8 @@ require "./requires" Log.setup_from_env(default_level: :warn, default_sources: "crystal.*") +{% if flag?(:execution_context) %} + Fiber::ExecutionContext.default.resize(Fiber::ExecutionContext.default_workers_count) +{% end %} + Crystal::Command.run diff --git a/src/compiler/crystal/compiler.cr b/src/compiler/crystal/compiler.cr index 1bbc2d4527b6..3293448bcbe3 100644 --- a/src/compiler/crystal/compiler.cr +++ b/src/compiler/crystal/compiler.cr @@ -83,7 +83,9 @@ module Crystal property? no_codegen = false # Maximum number of LLVM modules that are compiled in parallel - property n_threads : Int32 = {% if flag?(:preview_mt) %} + property n_threads : Int32 = {% if flag?(:execution_context) %} + Fiber::ExecutionContext.default_workers_count + {% elsif flag?(:preview_mt) %} ENV["CRYSTAL_WORKERS"]?.try(&.to_i?) || 4 {% elsif flag?(:win32) %} 1