Skip to content

Int -> UInt8#41

Open
THinnerichs wants to merge 5 commits into
masterfrom
feat/Int-UInt8
Open

Int -> UInt8#41
THinnerichs wants to merge 5 commits into
masterfrom
feat/Int-UInt8

Conversation

@THinnerichs
Copy link
Copy Markdown
Member

@THinnerichs THinnerichs commented Mar 14, 2025

  • RuleNode is now parametric and dynamically decides for the smallest type
    The default type for everything integer is not the concrete type Int (which defaults to Int64 on 64-bit machines) but now the abstract type Integer (for which UInt8 <: Integer and Int <: Integer holds)

  • I added smallest_Int_type, which iterates over possible types to return the smallest.

Why this is still a draft:
We have to decide what types we want to allow here—the more types we iterate over in smallest_Int_type, the slower the enumeration potentially. I will test this as soon as possible.

@THinnerichs THinnerichs requested a review from ReubenJ March 14, 2025 08:49
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 14, 2025

Codecov Report

❌ Patch coverage is 63.88889% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.07%. Comparing base (ebf0001) to head (800867b).
⚠️ Report is 62 commits behind head on master.

Files with missing lines Patch % Lines
src/rulenode.jl 63.88% 13 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #41      +/-   ##
==========================================
+ Coverage   75.36%   76.07%   +0.70%     
==========================================
  Files           2        2              
  Lines         203      209       +6     
==========================================
+ Hits          153      159       +6     
  Misses         50       50              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@THinnerichs
Copy link
Copy Markdown
Member Author

Defaulted to UInt8 in RuleNode constructor

@THinnerichs THinnerichs marked this pull request as ready for review March 14, 2025 09:45
Copy link
Copy Markdown
Member

@ReubenJ ReubenJ left a comment

Choose a reason for hiding this comment

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

Couple of questions, small changes. I'm also fine with the dynamic type parameter for a rulenode if you like.

Comment thread src/rulenode.jl
abstract type AbstractRuleNode end

# Interface to AbstractTrees.jl
# Integererface to AbstractTrees.jl
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Find and replace error? 😄

Comment thread src/rulenode.jl Outdated

# Default constructor
function RuleNode(ind::Integer, _val::Any, children::Vector{<:AbstractRuleNode}=AbstractRuleNode[])
new{smallest_Int_type(ind)}(ind, _val, children)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In favor of just defaulting to UInt8 here 👍

Comment thread src/rulenode.jl
@assert ex.head==:curly "Input to the @rulenode macro should be in the form of: 1{2,3}"
:(RuleNode(
# Interpolate the _value_ of the first rule (1 from 1{2,3})
# Integererpolate the _value_ of the first rule (1 from 1{2,3})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# Integererpolate the _value_ of the first rule (1 from 1{2,3})
# Interpolate the _value_ of the first rule (1 from 1{2,3})

Comment thread src/rulenode.jl Outdated
Comment on lines +602 to +616


"""
smallest_Int_type(n::Integer)

Finds the smallest type for the given integer and returns it.
"""
function smallest_Int_type(n::Integer)
for T in (UInt8, UInt16)
if typemin(T) ≤ n ≤ typemax(T)
return T
end
end
return Int
end No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
"""
smallest_Int_type(n::Integer)
Finds the smallest type for the given integer and returns it.
"""
function smallest_Int_type(n::Integer)
for T in (UInt8, UInt16)
if typemin(T) n typemax(T)
return T
end
end
return Int
end

Comment thread src/rulenode.jl
Evaluate immediately functionality is not yet supported by most of Herb.jl.
"""
RuleNode(ind::Int, _val::Any) = RuleNode(ind, _val, AbstractRuleNode[])
# RuleNode(ind::Integer, _val::Any) = RuleNode(ind, _val, AbstractRuleNode[])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why comment this?

Comment thread src/rulenode.jl

# Default constructor
function RuleNode(ind::Integer, _val::Any, children::Vector{<:AbstractRuleNode}=AbstractRuleNode[])
new{UInt8}(ind, _val, children)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd also be fine with using smallest_Int_type now that it's fast.

@ReubenJ
Copy link
Copy Markdown
Member

ReubenJ commented Mar 14, 2025

Also, just to note: this will have to be a breaking release (0.4.0) as any method that has expected ind of a RuleNode to be an Int (Int64) will break now that the type has been widened.

To see an example, run HerbSearch tests with this branch. Half the tests will fail due to Int typing on many methods.

Comment thread src/rulenode.jl
mutable struct RuleNode{T<:Integer} <: AbstractRuleNode
ind::T
_val::Any
children::Vector{AbstractRuleNode}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wondering if we should switch this to AbstractVector while we're at it. This opens us up to using StaticArrays.jl' SVector or MVector. Probably some performance to squeeze out there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants