Code Monkey home page Code Monkey logo

Comments (4)

onox avatar onox commented on July 21, 2024

I don't think it improves the readability and the non-short circuit operators may give the compiler more opportunities for optimizing the code.

from orka.

pjljvandelaar avatar pjljvandelaar commented on July 21, 2024

Hi Onox,

Your statement that the compiler has more opportunities for optimizing the code with non short circuit operators is invalid.

See e.g. https://www.adaic.org/resources/add_content/docs/95style/html/sec_5/5-5-5.html and

In the absence of short-circuit forms, Ada does not provide a guarantee of the order of expression evaluation, nor does the language guarantee that evaluation of a relational expression is abandoned when it becomes clear that it evaluates to False (for and) or True (for or).

and https://perso.telecom-paristech.fr/pautet/Ada95/chap04.htm

The way the expressions are written in lines 26 through 29, all of the expressions will be evaluated when the statement is executed. If, in the case of line 26, the value of Index is not 12, then the final result will be FALSE no matter what the rest of the expressions are and it would be a waste of time to evaluate them. Ada will continue blindly across the entire line evaluating all of the expressions and wasting time since it should know the final result based on the first comparison. There is however, a way to tell it to stop as soon as it knows the final answer, through use of the short circuit operators.

from orka.

pjljvandelaar avatar pjljvandelaar commented on July 21, 2024

To find places where membership tests are preferred, our software only matches with pattern that use short-circuit operators.

I noticed that your code can benefit from membership tests at some locations,
see e.g. orka/src/orka/implementation/orka-frame_graphs.adb

- if Resource.Input_Mode /= Not_Used and Resource.Input_Mode /= Mode then
+ if Resource.Input_Mode not in Not_Used | Mode then 

from orka.

onox avatar onox commented on July 21, 2024

and it would be a waste of time to evaluate them. Ada will continue blindly across the entire line evaluating all of the expressions

This information seems to be from the late 90s. Is this still the case with a modern version of GNAT? I would think that by using and and or you give the compiler more freedom to optimize.

see e.g. orka/src/orka/implementation/orka-frame_graphs.adb

Did not know I could combine an enum literal and a variable in membership test 😮

from orka.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.