Skip to content
This repository has been archived by the owner on Mar 26, 2023. It is now read-only.

Latest commit

 

History

History
126 lines (90 loc) · 4.71 KB

maglev_bootstrap.rdoc

File metadata and controls

126 lines (90 loc) · 4.71 KB

Maglev Bootstrap code.

The Maglev Bootstrap code consists of those ruby files loaded by src/kernel/kernel.rb. This Ruby code is compiled with the semantics defined in the rest of this file.

Multiple def of a method is allowed

The first def is used to generate bridge methods, and sends resolving to a bridge method will come to this implementation by default.

A subsequent def of the same method with an alternate argument signature will replace a bridge method with the given implementation, and will have no bridge methods generated for itself.

Special semantics for send of super

From Object.rb near line 64: During bootstrap, a send of super with no args specified passes an implicit block argument (the declared block parameter or nil), otherwise only the exact args to super are passed.

Outside of bootstrap, super alway passes an explicit or implicit block argument. See RubySuperNode in .mcz and Trac 454, 634.

Special semantics of ensure while in bootstrap:

From Object.rb near line 72: During bootstrap, a Ruby ensure translates to the Smalltalk ExecBlock>>ensure: semantics, and the ensure block will be executed after any rescue blocks run.

Outside of bootstrap, ensure translates to ExecBlock>>rubyEnsure: and the ensure block executes before rescue blocks higher in the stack are run.

Use of rubyEnsure: fixes Trac 720. Use of ensure: in bootstrap code makes the ensure faster .

Special bridge rules for send

From Object.rb near line 101: send#1*& and __send__#1*& are special cased in bridgeForPrimAllowed:, to have bridges during bootstrap. Any other implementations of send or __send__ get no bridge methods during bootstrap, to allow reimplementation of send for methods updating $~ or $_.

Redefinitions of some ‘private’ methods are disallowed after bootstrap

See Object.rb:

  • redefinition of __send__ disallowed by parser after bootstrap finished.

  • redefinition of __perform__ disallowed by parser after bootstrap finished.

  • redefinition of __perform_method disallowed after bootstrap

  • Attempts to reimplement block_given? disallowd after bootstrap

Extending these classes is not allowed after bootstrap

  • VariableContext

  • ExecBlock

  • GsNMethod

Constant resolution.

During bootstrap, the parser attempts to resolve constants at compile time, to generate more efficient code to access constants whose value never changes, such as String, Array. See the sends of __freeze_constants in a number of files which assists in the resolution of constants at compile time.

See also

  • RubyClassNameNode >> walkWithScope:

  • RubyColon2Node >> walkWithScope:isDefinedQ:

  • RubyColon3Node >> walkWithScope:isDefinedQ:

  • RubyConstDeclNode >> walkWithScope:

  • Module >> rubyConstAt:env:put:

Use of defined? is not allowed in bootstrap code.

A variable on left hand side of :: is not allowed in bootstrap code (see RubyColon2Node>>walkWithScope:isDefinedQ:).

Type.coerce_to optimizations

See RubyCallNode >> irForTypeCoerce3Args: in mcz/RubyCallNode.gs

If compiling bootstrap code we always optimize a call such as

Type.coerce_to(o , Integer, :to_int)

to

o _isInteger ifTrue:[ o ]
             ifFalse:[ Type.__coerce_to_Integer_to_int(o) ]

If not compiling bootstrap code, we attempt the optimization.

Class definitions

Automatic sends of #inherited, #method_added, are not done during bootstrap.

During bootstrap only, classes are left as ‘smalltalk modifiable’ in the first opening so that instVars with fixed offsets can be accumulated during the opening.

The first opening of a class or module which is found in the name space (i.e. was defined from Smalltalk) will delete any persistent environment 1 methods for the class.

See RubyCompiler>>defineClassNamed:rubyMethod:inScope:superclass:env:fixedIvs: and RubyCompiler>>defineModuleNamed:rubyMethod:inScope:env:

instVar references that would create a dynamic instVar are not allowd.

Enviroment 1 superclass of Symbol is changed to be Object near end of bootstrap, see RubyContext >> _fixSymbolSuperclass:.

Miscellaneous

LOADED_FEATURES accumulates files loaded during bootstrap and is reset to empty at end of bootstrap. See RubyContext>>_requirePrimitives_traceGlobals:traceLocals:env:reload:.

Some of the automatic coercion to Proc is not executed within bootstrap code. See comments in RubyLocalVarNode >> irBlockPassNode, and RubyBlockPassNode >> irNode.

Creation of a Binding is not allowed during bootstrap, see RubyVCallBindingNode>>irArgNodes.