Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion lib/typeprof/core/ast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def self.parse_rb(path, src)
raise unless raw_scope.type == :program_node

prism_source = result.source
file_context = FileContext.new(path, prism_source.code_units_cache(Encoding::UTF_16LE), result.comments)
file_context = FileContext.new(path, prism_source, result.comments)

cref = CRef::Toplevel
lenv = LocalEnv.new(file_context, cref, {}, [])
Expand Down
6 changes: 4 additions & 2 deletions lib/typeprof/core/ast/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(raw_node, lenv)
@ret = nil

@changes = ChangeSet.new(self, nil)
@diagnostics = Set.empty
@diagnostics = Set::EMPTY
end

attr_reader :lenv
Expand Down Expand Up @@ -104,6 +104,7 @@ def install_copy(genv)
@changes.reuse(self)
(@prev_node || raise).diagnostics.each do |diag|
diag.reuse(self)
@diagnostics = Set.empty if @diagnostics.equal?(Set::EMPTY)
@diagnostics << diag
end
each_subnode do |subnode|
Expand All @@ -129,11 +130,12 @@ def narrowings
end

def add_diagnostic(diag)
@diagnostics = Set.empty if @diagnostics.equal?(Set::EMPTY)
@diagnostics << diag
end

def remove_diagnostic(diag)
@diagnostics.delete(diag)
@diagnostics.delete(diag) unless @diagnostics.equal?(Set::EMPTY)
end

def diff(prev_node)
Expand Down
11 changes: 8 additions & 3 deletions lib/typeprof/core/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,17 @@ class Hash[K, V]
end

class FileContext
attr_reader :path, :code_units_cache, :comments
def initialize(path, code_units_cache = nil, comments = nil)
attr_reader :path, :comments
def initialize(path, prism_source = nil, comments = nil)
@path = path
@code_units_cache = code_units_cache
@prism_source = prism_source
@code_units_cache = nil
@comments = comments
end

def code_units_cache
@code_units_cache ||= @prism_source&.code_units_cache(Encoding::UTF_16LE)
end
end

class LocalEnv
Expand Down
2 changes: 2 additions & 0 deletions lib/typeprof/core/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,7 @@ def pretty_print(q)
end
q.text "]"
end

EMPTY = empty.freeze
end
end