Skip to content

Commit 0d523d8

Browse files
committed
Drops support for classic mode
This starts a series of patches in which we drop classic mode. The final result no longer has a const_missing callback, there is no hook/unhook, and so on. So, in this patch we remove the ability of configuring classic, but some of the code that remains will be further refactored.
1 parent 7762770 commit 0d523d8

File tree

8 files changed

+12
-94
lines changed

8 files changed

+12
-94
lines changed

activesupport/lib/active_support/dependencies/zeitwerk_integration.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require "set"
44
require "active_support/core_ext/string/inflections"
5+
require "zeitwerk"
56

67
module ActiveSupport
78
module Dependencies

guides/source/autoloading_and_reloading_constants.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -438,25 +438,3 @@ While in common names these operations match, if acronyms or custom inflection r
438438
### More Differences
439439

440440
There are some other subtle differences. Please check the [autoloading section](upgrading_ruby_on_rails.html#autoloading) of the _Upgrading Ruby on Rails_] guide for details.
441-
442-
Classic Mode is Deprecated
443-
--------------------------
444-
445-
Currently, it is still possible to use `classic` mode. However, `classic` is deprecated and will be eventually removed.
446-
447-
New applications should use `zeitwerk` mode (which is the default), and applications being upgraded are strongly encouraged to migrate to `zeitwerk` mode. Please check the [_Upgrading Ruby on Rails_](upgrading_ruby_on_rails.html#autoloading) guide for details.
448-
449-
Opting Out
450-
----------
451-
452-
Applications can load Rails 6 defaults and still use the `classic` autoloader this way:
453-
454-
```ruby
455-
# config/application.rb
456-
config.load_defaults 6.0
457-
config.autoloader = :classic
458-
```
459-
460-
That may be handy if upgrading to Rails 6 in different phases, but `classic` mode is discouraged for new applications.
461-
462-
`zeitwerk` mode is not available in versions of Rails prior to 6.0.

guides/source/configuring.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,6 @@ numbers. It also filters out sensitive values of database columns when call `#in
159159
160160
* `config.time_zone` sets the default time zone for the application and enables time zone awareness for Active Record.
161161
162-
* `config.autoloader` sets the autoloading mode. This option defaults to `:zeitwerk` when `config.load_defaults` is called with `6.0` or greater. Applications can still use the classic autoloader by setting this value to `:classic` after loading the framework defaults:
163-
164-
```ruby
165-
config.load_defaults 6.0
166-
config.autoloader = :classic
167-
```
168-
169162
### Configuring Assets
170163
171164
* `config.assets.enabled` a flag that controls whether the asset

railties/lib/rails/application/configuration.rb

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Configuration < ::Rails::Engine::Configuration
2323
:require_master_key, :credentials, :disable_sandbox, :add_autoload_paths_to_load_path,
2424
:rake_eager_load
2525

26-
attr_reader :encoding, :api_only, :loaded_config_version, :autoloader
26+
attr_reader :encoding, :api_only, :loaded_config_version
2727

2828
def initialize(*)
2929
super
@@ -69,7 +69,6 @@ def initialize(*)
6969
@credentials = ActiveSupport::OrderedOptions.new
7070
@credentials.content_path = default_credentials_content_path
7171
@credentials.key_path = default_credentials_key_path
72-
@autoloader = :classic
7372
@disable_sandbox = false
7473
@add_autoload_paths_to_load_path = true
7574
@permissions_policy = nil
@@ -128,8 +127,6 @@ def load_defaults(target_version)
128127
when "6.0"
129128
load_defaults "5.2"
130129

131-
self.autoloader = :zeitwerk if RUBY_ENGINE == "ruby"
132-
133130
if respond_to?(:action_view)
134131
action_view.default_enforce_utf8 = false
135132
end
@@ -155,8 +152,6 @@ def load_defaults(target_version)
155152
when "6.1"
156153
load_defaults "6.0"
157154

158-
self.autoloader = :zeitwerk if %w[ruby truffleruby].include?(RUBY_ENGINE)
159-
160155
if respond_to?(:active_record)
161156
active_record.has_many_inversing = true
162157
active_record.legacy_connection_handling = false
@@ -365,18 +360,6 @@ def permissions_policy(&block)
365360
end
366361
end
367362

368-
def autoloader=(autoloader)
369-
case autoloader
370-
when :classic
371-
@autoloader = autoloader
372-
when :zeitwerk
373-
require "zeitwerk"
374-
@autoloader = autoloader
375-
else
376-
raise ArgumentError, "config.autoloader may be :classic or :zeitwerk, got #{autoloader.inspect} instead"
377-
end
378-
end
379-
380363
def default_log_file
381364
path = paths["log"].first
382365
unless File.exist? File.dirname path

railties/lib/rails/application/finisher.rb

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require "active_support/core_ext/string/inflections"
44
require "active_support/core_ext/array/conversions"
5+
require "zeitwerk"
56

67
module Rails
78
class Application
@@ -39,14 +40,10 @@ module Finisher
3940
example = autoloaded.first
4041
example_klass = example.constantize.class
4142

42-
if config.autoloader == :zeitwerk
43-
ActiveSupport::DescendantsTracker.clear
44-
ActiveSupport::Dependencies.clear
43+
ActiveSupport::DescendantsTracker.clear
44+
ActiveSupport::Dependencies.clear
4545

46-
unload_message = "#{these} autoloaded #{constants} #{have} been unloaded."
47-
else
48-
unload_message = "`config.autoloader` is set to `#{config.autoloader}`. #{these} autoloaded #{constants} would have been unloaded if `config.autoloader` had been set to `:zeitwerk`."
49-
end
46+
unload_message = "#{these} autoloaded #{constants} #{have} been unloaded."
5047

5148
ActiveSupport::Deprecation.warn(<<~WARNING)
5249
Initialization autoloaded the #{constants} #{enum}.
@@ -76,10 +73,8 @@ module Finisher
7673
end
7774

7875
initializer :let_zeitwerk_take_over do
79-
if config.autoloader == :zeitwerk
80-
require "active_support/dependencies/zeitwerk_integration"
81-
ActiveSupport::Dependencies::ZeitwerkIntegration.take_over(enable_reloading: !config.cache_classes)
82-
end
76+
require "active_support/dependencies/zeitwerk_integration"
77+
ActiveSupport::Dependencies::ZeitwerkIntegration.take_over(enable_reloading: !config.cache_classes)
8378
end
8479

8580
# Setup default session store if not already set in config/application.rb
@@ -113,10 +108,7 @@ module Finisher
113108
initializer :eager_load! do
114109
if config.eager_load
115110
ActiveSupport.run_load_hooks(:before_eager_load, self)
116-
# Checks defined?(Zeitwerk) instead of zeitwerk_enabled? because we
117-
# want to eager load any dependency managed by Zeitwerk regardless of
118-
# the autoloading mode of the application.
119-
Zeitwerk::Loader.eager_load_all if defined?(Zeitwerk)
111+
Zeitwerk::Loader.eager_load_all
120112
config.eager_load_namespaces.each(&:eager_load!)
121113
end
122114
end

railties/lib/rails/autoloaders.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require "active_support/dependencies/zeitwerk_integration"
4+
require "zeitwerk"
45

56
module Rails
67
module Autoloaders # :nodoc:
@@ -41,7 +42,7 @@ def log!
4142
end
4243

4344
def zeitwerk_enabled?
44-
Rails.configuration.autoloader == :zeitwerk
45+
true
4546
end
4647
end
4748
end

railties/test/application/configuration_test.rb

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,6 @@ def index
12191219
test "autoloaders" do
12201220
app "development"
12211221

1222-
config = Rails.application.config
12231222
assert Rails.autoloaders.zeitwerk_enabled?
12241223
assert_instance_of Zeitwerk::Loader, Rails.autoloaders.main
12251224
assert_equal "rails.main", Rails.autoloaders.main.tag
@@ -1228,24 +1227,6 @@ def index
12281227
assert_equal [Rails.autoloaders.main, Rails.autoloaders.once], Rails.autoloaders.to_a
12291228
assert_equal ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector, Rails.autoloaders.main.inflector
12301229
assert_equal ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector, Rails.autoloaders.once.inflector
1231-
1232-
config.autoloader = :classic
1233-
assert_not Rails.autoloaders.zeitwerk_enabled?
1234-
assert_nil Rails.autoloaders.main
1235-
assert_nil Rails.autoloaders.once
1236-
assert_equal 0, Rails.autoloaders.count
1237-
1238-
config.autoloader = :zeitwerk
1239-
assert Rails.autoloaders.zeitwerk_enabled?
1240-
assert_instance_of Zeitwerk::Loader, Rails.autoloaders.main
1241-
assert_equal "rails.main", Rails.autoloaders.main.tag
1242-
assert_instance_of Zeitwerk::Loader, Rails.autoloaders.once
1243-
assert_equal "rails.once", Rails.autoloaders.once.tag
1244-
assert_equal [Rails.autoloaders.main, Rails.autoloaders.once], Rails.autoloaders.to_a
1245-
assert_equal ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector, Rails.autoloaders.main.inflector
1246-
assert_equal ActiveSupport::Dependencies::ZeitwerkIntegration::Inflector, Rails.autoloaders.once.inflector
1247-
1248-
assert_raises(ArgumentError) { config.autoloader = :unknown }
12491230
end
12501231

12511232
test "config.action_view.cache_template_loading with cache_classes default" do

railties/test/application/zeitwerk_integration_test.rb

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def decorated?
2626
deps.singleton_class < deps::ZeitwerkIntegration::Decorations
2727
end
2828

29-
test "ActiveSupport::Dependencies is decorated by default" do
29+
test "ActiveSupport::Dependencies is decorated" do
3030
boot
3131

3232
assert decorated?
@@ -36,17 +36,6 @@ def decorated?
3636
assert_equal [Rails.autoloaders.main, Rails.autoloaders.once], Rails.autoloaders.to_a
3737
end
3838

39-
test "ActiveSupport::Dependencies is not decorated in classic mode" do
40-
add_to_config "config.autoloader = :classic"
41-
boot
42-
43-
assert_not decorated?
44-
assert_not Rails.autoloaders.zeitwerk_enabled?
45-
assert_nil Rails.autoloaders.main
46-
assert_nil Rails.autoloaders.once
47-
assert_equal 0, Rails.autoloaders.count
48-
end
49-
5039
test "autoloaders inflect with Active Support" do
5140
app_file "config/initializers/inflections.rb", <<-RUBY
5241
ActiveSupport::Inflector.inflections(:en) do |inflect|

0 commit comments

Comments
 (0)