Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate YARP (aka Prism) #1213

Merged
merged 52 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
3d38499
Get YARP building and parsing some basic calls
seven1m Sep 6, 2023
8574221
Get examples/fib.rb parsing
seven1m Sep 6, 2023
0e94c34
Get examples/boardslam.rb parsing
seven1m Sep 7, 2023
26dd097
Get the spec runner parsing
seven1m Sep 10, 2023
de0278c
Get test/natalie/method_test.rb parsing
seven1m Sep 10, 2023
7ddfbc9
Use simpler code for getting parameters in order
seven1m Sep 10, 2023
2a5ac56
Get test/natalie/assign_test.rb parsing
seven1m Sep 11, 2023
671c9e4
Add some nokogiri dependencies temporarily
seven1m Sep 11, 2023
5a24cf5
Get test/natalie/bootstrap_test.rb parsing
seven1m Sep 11, 2023
c77c0ca
Get test/natalie/class_var_test.rb parsing
seven1m Sep 11, 2023
a1c634a
Update YARP
seven1m Sep 12, 2023
30156a9
Update translation for new YARP updates
seven1m Sep 12, 2023
7c0aa77
Get test/natalie/complex_test.rb parsing
seven1m Sep 12, 2023
39a5c2e
Revert "Add some nokogiri dependencies temporarily"
seven1m Sep 12, 2023
3c750b8
Store YARP generated sources in our repo
seven1m Sep 12, 2023
b8dc641
Fix syntax to work with Ruby 3.0
seven1m Sep 12, 2023
82453a2
Get test/natalie/defined_test.rb parsing
seven1m Sep 13, 2023
2dc94a1
Fix parsing of escape sequences in symbols
seven1m Sep 13, 2023
e317ffd
Fix while and until parsing, fixes test/natalie/json_test.rb
seven1m Sep 13, 2023
465540b
Show more helpful message for RaiseErrorExpectation
seven1m Sep 14, 2023
924d778
Fix parsing of for and redo
seven1m Sep 14, 2023
10b3379
Remove kludge for issue #1201
seven1m Sep 14, 2023
0527d4b
Parse rational nodes
seven1m Sep 14, 2023
1c898a4
Fix parsing of super with block
seven1m Sep 14, 2023
95c94af
Parse interpolated symbols
seven1m Sep 14, 2023
ef371e6
Fix parsing of class var writes
seven1m Sep 14, 2023
2b82a84
Don't rebuild YARP with rake clean (use clobber)
seven1m Sep 14, 2023
11b26d9
Parse __LINE__
seven1m Sep 14, 2023
0bf27af
Fix missing comma in lib/openssl.rb
seven1m Sep 14, 2023
0bff6b2
Raise a SyntaxError for MissingNode
seven1m Sep 14, 2023
fab8d86
Parse undef
seven1m Sep 14, 2023
6de002d
Match interpolated string node parsing with NatalieParser
seven1m Sep 14, 2023
5278d83
Fix yarp building on macos
seven1m Sep 15, 2023
792ddb4
Fix bug with interpolated node extraction
seven1m Sep 14, 2023
fc61795
Fix parsing of $' to match NatalieParser
seven1m Sep 15, 2023
ffb5f70
Fix parsing of rescue in modifier form
seven1m Sep 15, 2023
b250f8e
Update YARP
seven1m Sep 15, 2023
4910d6b
Fix parsing of AliasMethodNode
seven1m Sep 15, 2023
6bbdf23
Fix parsing of module names
seven1m Sep 15, 2023
bcf85e9
Fix parsing of escape sequences in interpolated regex
seven1m Sep 15, 2023
f66a54d
Fix parsing of regexp flags e, u, s, and n
seven1m Sep 15, 2023
4c40aca
Fix parsing of empty parentheses
seven1m Sep 15, 2023
391fa28
Fix $` parsing
seven1m Sep 15, 2023
90dd862
Fix (kinda) parsing of regexp match write node
seven1m Sep 15, 2023
0653488
Fix parsing of retry
seven1m Sep 15, 2023
5fe457c
Update YARP
seven1m Sep 19, 2023
26f2e6e
Remove hack for Regexp options parsing
seven1m Sep 19, 2023
fe5e469
Raise a slightly better syntax error
seven1m Sep 19, 2023
11159b5
Fix parsing of BlockArgumentNode
seven1m Sep 20, 2023
cd3714c
Raise SyntaxError for case without when
seven1m Sep 20, 2023
92bfeb3
Remove NatalieParser
seven1m Sep 21, 2023
4e9ccf8
Fix parsing of other line continuation scenarios
seven1m Sep 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[submodule "ext/onigmo"]
path = ext/onigmo
url = https://github.com/k-takata/Onigmo.git
[submodule "ext/natalie_parser"]
path = ext/natalie_parser
url = https://github.com/natalie-lang/natalie_parser
[submodule "ext/tm"]
path = ext/tm
url = https://github.com/seven1m/tm
[submodule "ext/zlib"]
path = ext/zlib
url = https://github.com/madler/zlib
[submodule "ext/yarp"]
path = ext/yarp
url = https://github.com/ruby/yarp
99 changes: 62 additions & 37 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ task default: :build

DEFAULT_BUILD_TYPE = 'debug'.freeze
SO_EXT = RUBY_PLATFORM =~ /darwin/ ? 'bundle' : 'so'
SO_EXT2 = RUBY_PLATFORM =~ /darwin/ ? 'dylib' : 'so'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI this is called DLEXT in RbConfig terms

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

SRC_DIRECTORIES = Dir.new('src').children.select { |p| File.directory?(File.join('src', p)) }

desc 'Build Natalie'
Expand All @@ -13,12 +14,12 @@ task :build do
end

desc 'Build Natalie with no optimization and all warnings (default)'
task build_debug: %i[set_build_debug libnatalie parser_c_ext ctags] do
task build_debug: %i[set_build_debug libnatalie yarp_c_ext ctags] do
puts 'Build mode: debug'
end

desc 'Build Natalie with release optimizations enabled and warnings off'
task build_release: %i[set_build_release libnatalie parser_c_ext] do
task build_release: %i[set_build_release libnatalie yarp_c_ext] do
puts 'Build mode: release'
end

Expand All @@ -32,10 +33,6 @@ task :clean do
rm_rf 'build/generated'
rm_rf 'build/libnatalie_base.a'
rm_rf "build/libnatalie_base.#{SO_EXT}"
rm_rf 'build/natalie_parser'
rm_rf 'build/libnatalie_parser.a'
rm_rf "build/natalie_parser.#{SO_EXT}"
rm_rf 'build/natalie_parser.bundle'
rm_rf Rake::FileList['build/*.o']
end

Expand Down Expand Up @@ -96,8 +93,8 @@ end
desc 'Build the self-hosted version of Natalie at bin/nat'
task bootstrap: [:build, 'bin/nat']

desc 'Build MRI C Extension for the Natalie Parser'
task parser_c_ext: ["build/natalie_parser.#{SO_EXT}", "build/libnatalie_parser.#{SO_EXT}"]
desc 'Build MRI C Extension for YARP'
task yarp_c_ext: ["build/librubyparser.#{SO_EXT2}", "build/yarp/ext/yarp/yarp.#{SO_EXT}"]

desc 'Show line counts for the project'
task :cloc do
Expand Down Expand Up @@ -134,6 +131,38 @@ task tidy: %i[build tidy_internal]
desc 'Lint GC visiting code'
task gc_lint: %i[build gc_lint_internal]

YARP_TEMPLATED_SOURCES = [
'ext/yarp/api_node.c',
'src/token_type.c',
'src/serialize.c',
'src/node.c',
'src/prettyprint.c',
'lib/yarp/node.rb',
'lib/yarp/serialize.rb',
'lib/yarp/mutation_visitor.rb',
'include/yarp/ast.h',
].freeze

desc 'Generate YARP sources from templates (do this when updating YARP)'
task :yarp_templated_sources do
build_dir = File.expand_path('build/yarp', __dir__)
rm_rf build_dir
cp_r 'ext/yarp', build_dir
sh <<-END
cd #{build_dir} && \
bundle install && \
rake templates
END
gen_dir = File.join(__dir__, 'ext/yarp-generated')
rm_rf gen_dir
YARP_TEMPLATED_SOURCES.each do |src|
full_dest = File.join(gen_dir, src)
dir = File.split(full_dest).first
mkdir_p dir unless File.exist?(dir)
cp File.join(build_dir, src), full_dest
end
end

# # # # Docker Tasks (used for CI) # # # #

DOCKER_FLAGS =
Expand Down Expand Up @@ -256,7 +285,8 @@ task libnatalie: [
:build_dir,
'build/zlib/libz.a',
'build/onigmo/lib/libonigmo.a',
'build/libnatalie_parser.a',
'build/librubyparser.a',
"build/librubyparser.#{SO_EXT2}",
'build/generated/numbers.rb',
:primary_objects,
:ruby_objects,
Expand All @@ -275,7 +305,6 @@ multitask ruby_objects: RUBY_OBJECT_FILES
multitask special_objects: SPECIAL_OBJECT_FILES

file 'build/libnatalie.a' => %w[
build/libnatalie_parser.a
build/libnatalie_base.a
build/onigmo/lib/libonigmo.a
] do |t|
Expand Down Expand Up @@ -322,17 +351,6 @@ file 'build/zlib/libz.a' do
SH
end

file 'build/libnatalie_parser.a' => Rake::FileList['ext/natalie_parser/**/*.{hpp,cpp}'] do
build_dir = File.expand_path('build/natalie_parser', __dir__)
rm_rf build_dir
cp_r 'ext/natalie_parser', build_dir
sh <<-SH
cd #{build_dir} && \
BUILD=release rake library && \
cp #{build_dir}/build/libnatalie_parser.a #{File.expand_path('build', __dir__)}
SH
end

file 'build/generated/numbers.rb' do |t|
f1 = Tempfile.new(%w[numbers .cpp])
f2 = Tempfile.create('numbers')
Expand Down Expand Up @@ -380,10 +398,6 @@ rule '.c.o' => 'src/%n' do |t|
sh "#{cc} -g -fPIC -c -o #{t.name} #{t.source}"
end

rule %r{natalie_parser/.*\.cpp\.o$} => ['src/natalie_parser/%n'] + HEADERS do |t|
sh "#{cxx} #{cxx_flags.join(' ')} -std=#{STANDARD} -c -o #{t.name} #{t.source}"
end

rule '.cpp.o' => ['src/%{build/,}X'] + HEADERS do |t|
subdir = File.split(t.name).first
mkdir_p subdir unless File.exist?(subdir)
Expand All @@ -394,27 +408,38 @@ rule '.rb.o' => ['.rb.cpp'] + HEADERS do |t|
sh "#{cxx} #{cxx_flags.join(' ')} -std=#{STANDARD} -c -o #{t.name} #{t.source}"
end

rule '.rb.cpp' => ['src/%{build\/generated/,}X', "build/natalie_parser.#{SO_EXT}"] do |t|
rule '.rb.cpp' => ['src/%{build\/generated/,}X'] do |t|
subdir = File.split(t.name).first
mkdir_p subdir unless File.exist?(subdir)
sh "bin/natalie --write-obj #{t.name} #{t.source}"
end

file "build/natalie_parser.#{SO_EXT}" => 'build/libnatalie_parser.a' do
build_dir = File.expand_path('build/natalie_parser', __dir__)
file "build/librubyparser.#{SO_EXT2}" => ['build/librubyparser.a']

file 'build/librubyparser.a' => ["build/yarp/ext/yarp/yarp.#{SO_EXT}"] do
build_dir = File.expand_path('build/yarp', __dir__)
cp "#{build_dir}/build/librubyparser.a", File.expand_path('build', __dir__)
cp "#{build_dir}/build/librubyparser.#{SO_EXT2}", File.expand_path('build', __dir__)
end

file "build/yarp/ext/yarp/yarp.#{SO_EXT}" => Rake::FileList['ext/yarp/**/*.{h,c,rb}'] do
build_dir = File.expand_path('build/yarp', __dir__)
rm_rf build_dir
cp_r 'ext/yarp', build_dir
Rake::FileList['ext/yarp-generated/**/*.{rb,c,h}'].each do |path|
dest = File.join(build_dir, path.sub(%r{^ext/yarp-generated}, ''))
cp path, dest
end
File.write(File.join(build_dir, 'rakelib/test.rake'), '') # disable this task since it tries to load ruby_memcheck
sh <<-SH
cd #{build_dir} && \
rake parser_c_ext && \
cp #{build_dir}/ext/natalie_parser/natalie_parser.#{SO_EXT} #{File.expand_path('build', __dir__)}
make && \
cd ext/yarp && \
ruby extconf.rb && \
make
SH
end

# FIXME: should we rename to libnatalie_parser in the NatalieParser project?
file "build/libnatalie_parser.#{SO_EXT}" => "build/natalie_parser.#{SO_EXT}" do |t|
build_dir = File.expand_path('build/natalie_parser', __dir__)
sh "cp #{build_dir}/ext/natalie_parser/natalie_parser.#{SO_EXT} #{File.expand_path('build', __dir__)}/libnatalie_parser.#{SO_EXT}"
end

task :tidy_internal do
sh "clang-tidy --warnings-as-errors='*' #{PRIMARY_SOURCES.exclude('src/dtoa.c')}"
end
Expand Down Expand Up @@ -479,6 +504,6 @@ def include_paths
File.expand_path('ext/tm/include', __dir__),
File.expand_path('build', __dir__),
File.expand_path('build/onigmo/include', __dir__),
File.expand_path('build/natalie_parser/include', __dir__),
File.expand_path('build/yarp/include', __dir__),
]
end
1 change: 0 additions & 1 deletion ext/natalie_parser
Submodule natalie_parser deleted from 3ddd39
1 change: 1 addition & 0 deletions ext/yarp
Submodule yarp added at 1ba824
Loading