Skip to content

Commit

Permalink
Add Method#const_addeed.
Browse files Browse the repository at this point in the history
  • Loading branch information
itarato committed Jun 8, 2023
1 parent 7e07d2b commit 20f253f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Compatibility:
* Add `String#bytesplice` (#3039, @itarato).
* Add `String#byteindex` and `String#byterindex` (#3039, @itarato).
* Add implementations of `rb_proc_call_with_block`, `rb_proc_call_kw`, `rb_proc_call_with_block_kw` and `rb_funcall_with_block_kw` (#3068, @andrykonchin).
* Add `Module#const_added` (#3039, @itarato).

Performance:

Expand Down
2 changes: 2 additions & 0 deletions spec/truffleruby.next-specs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ spec/ruby/core/string/bytesplice_spec.rb

spec/ruby/core/string/byteindex_spec.rb
spec/ruby/core/string/byterindex_spec.rb

spec/ruby/core/module/const_added_spec.rb
12 changes: 10 additions & 2 deletions src/main/java/org/truffleruby/core/module/ModuleFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.truffleruby.RubyLanguage;
import org.truffleruby.collections.ConcurrentOperations;
import org.truffleruby.collections.ConcurrentWeakSet;
import org.truffleruby.core.CoreLibrary;
import org.truffleruby.core.encoding.Encodings;
import org.truffleruby.core.encoding.TStringUtils;
import org.truffleruby.core.kernel.KernelNodes;
Expand Down Expand Up @@ -483,7 +484,7 @@ private RubyConstant setConstantInternal(RubyContext context, Node currentNode,
return null;
}
}
newConstant = newConstant(currentNode, name, value, autoload, previous);
newConstant = newConstant(context, currentNode, name, value, autoload, previous);
} while (!ConcurrentOperations.replace(constants, name, previousEntry, new ConstantEntry(newConstant)));

if (previousEntry != null) {
Expand All @@ -497,11 +498,18 @@ private RubyConstant setConstantInternal(RubyContext context, Node currentNode,
return autoload ? newConstant : previous;
}

private RubyConstant newConstant(Node currentNode, String name, Object value, boolean autoload,
private RubyConstant newConstant(RubyContext context, Node currentNode, String name, Object value, boolean autoload,
RubyConstant previous) {
final boolean isPrivate = previous != null && previous.isPrivate();
final boolean isDeprecated = previous != null && previous.isDeprecated();
final SourceSection sourceSection = currentNode != null ? currentNode.getSourceSection() : null;

final CoreLibrary coreLibrary = context.getCoreLibrary();
if (currentNode != null && coreLibrary != null && coreLibrary.isLoaded()) {
final RubySymbol constSymbol = context.getLanguageSlow().getSymbol(name);
RubyContext.send(currentNode, rubyModule, "const_added", constSymbol);
}

return new RubyConstant(rubyModule, name, value, isPrivate, autoload, isDeprecated, sourceSection);
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/ruby/truffleruby/core/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def prepend(*modules)
self
end

private def const_added(name)
end

def const_defined?(name, inherit = true)
Primitive.module_const_defined?(self, name, inherit, true)
end
Expand Down

0 comments on commit 20f253f

Please sign in to comment.